package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.BaseIdDTO;
import com.winshare.saleAssistant.domain.dto.req.MaterialCreateDTO;
import com.winshare.saleAssistant.domain.dto.req.MaterialQueryDTO;
import com.winshare.saleAssistant.domain.dto.req.MaterialUpdateDTO;
import com.winshare.saleAssistant.service.MaterialService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/material")
@CrossOrigin
@Api(value = "物料控制类", description = "物料控制类")
public class MaterialController {

    private final MaterialService materialService;

    public MaterialController(MaterialService materialService) {
        this.materialService = materialService;
    }

    @PostMapping("/save")
   @ApiOperation(value = "新增物料接口")
    public LogicResponse save(@RequestBody @Validated MaterialCreateDTO materialCreateDTO) {
        materialService.saveMaterial(materialCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
   @ApiOperation(value = "修改物料接口",notes = "修改物料接口")
    public LogicResponse update(@RequestBody @Validated MaterialUpdateDTO materialUpdateDTO) {
        materialService.updateMaterial(materialUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除物料接口",notes = "删除物料接口")
    public LogicResponse delete(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        materialService.deleteMaterial(baseIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个物料或物料分类详情")
    public LogicResponse getMaterialDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(materialService.getMaterialDetail(baseIdDTO));
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取物料分类或文件列表", notes = "获取物料分类或文件列表")
    public LogicResponse queryMaterialPage(@RequestBody @Validated MaterialQueryDTO materialQueryDTO) {
        return LogicResponse.success(materialService.getMaterialList(materialQueryDTO));
    }
}
